
/***************************************************************************
 *   jell - library                                                        *
 *                                                                         *
 *   Copyright (C) 2008 by kuerant                                         *
 *                         <kuerant@gmail.com>                             *
 *                                                                         *
 *   This library is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   This library is distributed in the hope that it will be usefull, but  *
 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      *
 *   Library General Public License for more details.                      *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this library; if not, write to the Free Software   *
 *   Foundation, Inc., 59 Temple Place - Suite 330, Boston,                *
 *   MA 02111-1307, USA                                                    *
 ***************************************************************************/

#ifndef JEFI_NET_HPP
#define JEFI_NET_HPP

#include "jell/address.hpp"
#include "jell/allocator.hpp"
#include "jell/buf.hpp"
#include "jell/exception.hpp"
#include "jell/logger.hpp"

#include "jell/buf_handler.hpp"
#include "jell/event_handler.hpp"

namespace   jell
{
    class   Jelly;

    class   NetJell
    {
    public  :
        ~NetJell();
        static  NetJell*    create(void);

    public  :
        void    connect(const Address&) throw (JellException);
        void    listen(const Address&) throw (JellException);
        void    shutdown(const Address&) throw (JellException);
        void    shutdown(void) throw (JellException);

        void    run(void) throw (JellException);

    public  :
        // asynchronous call
        void    send(const Address&, Buf&, int timeout_in_seconds = -1) throw (JellException);
        void    recv(Address&, Buf&, int timeout_in_seconds = -1) throw (JellException);

        // synchronous call
        void    sendto(const Address&, Buf&, int timeout_in_seconds = -1) throw (JellException);
        void    recvfrom(Address&, Buf&, int timeout_in_seconds = -1) throw (JellException);

    public  :
        Allocator&  allocator() throw (JellException);

    public  :
        void    addBufHandler(BufHandler&) throw (JellException);
        void    addEventHandler(EventHandler&) throw (JellException);

    public  :
        void    setLogger(Logger*);
        Logger* getLogger(void);

    private :
        NetJell();

    private :
        NetJell(const NetJell&);
        NetJell&    operator=(const NetJell&);

    private :
        Jelly*   jelly;
    };  // class Net
}   // namespace jell

#endif  // JEFI_NET_JELL_HPP

